﻿// ***********************************************************************
// Assembly         : MVC4Portal
// Author           : LJO+01 (Laurent Jordi)
// Created          : 06-05-2013
// Last Modified By : LJO+01 (Laurent Jordi)
// Last Modified On : 06-05-2013
// ***********************************************************************
// <copyright file="_Controllers_Base.cs" company="Copyright © Innovacall 2011">
//     Copyright (c) Copyright © Innovacall 2011. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Web.Security;
using EmitMapper;
using InnovaApp.Layers.CommonLayer;
using InnovaApp.Layers.DataLayer;
using InnovaApp.Layers.DomainLayer;
using InnovaApp.Layers.ResourcesLayer.Properties;
using InnovaApp.Portals.MVC4Portal.Models.MetaModels.ContactManagement;
using INNOVACALL.Framework.Common;
using INNOVACALL.Framework.Common.HTMLHelpers;
using INNOVACALL.Framework.Common.MVCHelpers;

namespace InnovaApp.Portals.MVC4Portal.Controllers.ViewControllers
{
    /// <summary>
    /// Classe de base dont doivent hériter tous les controleurs
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [CacheManager(enCacheMode.NoCache)]
    public abstract class _ViewControllers_Base<T> : InnovaApp.Layers.CommonLayer.Controllers.ViewControllers._ViewControllers_Base<T> where T : InnovaApp.Layers.CommonLayer.Models.ViewModels._ViewModels_Base
    {
        /// <summary>
        /// Currents the contact get.
        /// </summary>
        /// <param name="_dataContext">The _data context.</param>
        /// <returns>ContactViewer_MetaModel.</returns>
        /// <exception cref="INNOVACALL.Framework.Common.InnovacallExceptions.DataIntegrityException"></exception>
        internal ContactViewer_MetaModel CurrentContactGet(DataRepositories _dataContext)
        {
            string eMethod = eMethodBase + "(_Controllers_Base)CurrentContactGet";
            object eParameters = new { @_dataContext = "[DataContext]" };

            ContactViewer_MetaModel toReturn = new ContactViewer_MetaModel();
            Contact dbContact = _dataContext.InnoAppUser_Rep.GetById((Guid)Membership.GetUser().ProviderUserKey).Contact.FirstOrDefault();
            if (dbContact == null)
            {
                throw new INNOVACALL.Framework.Common.InnovacallExceptions.DataIntegrityException(eMethod, eParameters, Resources.View_All_CustomerMustBeSetBefore);
            }
            toReturn = ObjectMapperManager.DefaultInstance.GetMapper<Contact, ContactViewer_MetaModel>().Map(dbContact);
            toReturn.Genre = StringEnum.GetStringValue(EnumTools.EnumTypeTo<enGenres>(dbContact.FK_Genre));
            return toReturn;
        }
    }
}
